"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".

Replace this with more appropriate tests for your application.
"""

from django.test import TestCase

from space.game import models
from space.game import controllers
from django.contrib.auth.models import User
from math import floor
from random import seed, random
from django.conf import settings
seed()


class ResearchTest(TestCase):

    def test_create_research(self):

        user = User()
        user.username = 'Grepsd'
        user.save()

        tech    = models.Technology()
        tech.name   = 'Weaponery'
        tech.save()

        research = models.Research()
        research.technology = tech
        research.user = user
        research.save()

        pre_up_level = research.level
        research.up()

        self.assertEquals(research.level, pre_up_level + 1)

class PlanetTest(TestCase):

    def test_create_planet(self):

        u = User()
        u.username = 'Grepsd'
        u.save()

        p1 = models.Planet()
        p1.user = u
        iteration = 1
        while iteration < 10000:
            p1.position = int(floor(random() * 15))
            s = p1.get_controller().generate_size()
            size = settings.PLANET_SIZE_BY_POSITION[p1.position]
            if s < size[1] or s > size[2]:
                raise Exception("The size of the planet isn't in the boundaries.")
            iteration += 1
